{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    }
   },
   "outputs": [],
   "source": [
    "#load \"..\\Extension\\LoadBaseTool.csx\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`<<=` 操作符\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "100\n",
      "1000\n",
      "10000\n",
      "100000\n",
      "1000000\n",
      "10000000\n",
      "100000000\n",
      "1000000000\n",
      "10000000000\n"
     ]
    }
   ],
   "source": [
    "int _index = 1;\n",
    "for(int i = 0; i < 10; i++)\n",
    "{\n",
    "    _index <<= 1;\n",
    "    Console.WriteLine($\"{_index:B}\");\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`int` 是值类型，且 `C#` 默认使用值传递，此时相当于复制了一个 `@int` 值出来，此处的 `_value` 和 `@int` 完全没有任何关系。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "public int Add(int _value) => ++_value;\n",
    "\n",
    "int @int = 10;\n",
    "Add(@int).Dump();\n",
    "@int.Dump();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "类型转换的时候，本质上还是二进制之间的计算。\n",
    "\n",
    "当超过 `uint` 范围的 `ulong` 强制转换为 `uint` 类型时，只会取低 `32` 位。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "33 || 100000000000000000000000000000000 || 4294967296\n",
      "01 || 00000000000000000000000000000000 || 0\n"
     ]
    }
   ],
   "source": [
    "ulong @ulong = (ulong)uint.MaxValue+1;\n",
    "uint @uint = (uint)@ulong;\n",
    "Console.WriteLine($\"{$\"{@ulong:b}\".Length} || {@ulong:b} || {@ulong}\");\n",
    "Console.WriteLine($\"{$\"{@uint:b}\".Length:00} || {@uint:b32} || {@uint}\");"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "当超过 `long` 范围的 `ulong` 被强制转换为 `long` 类型时，以补码的形式表示。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "dotnet_interactive": {
     "language": "csharp"
    },
    "polyglot_notebook": {
     "kernelName": "csharp"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "64 || 1000000000000000000000000000000000000000000000000000000000000000 || 9223372036854775808\n",
      "64 || 1000000000000000000000000000000000000000000000000000000000000000 || -9223372036854775808\n"
     ]
    }
   ],
   "source": [
    "ulong @ulong = (ulong)long.MaxValue + 1;\n",
    "long @long = (long)@ulong;\n",
    "Console.WriteLine($\"{$\"{@ulong:b}\".Length} || {@ulong:b} || {@ulong}\");\n",
    "Console.WriteLine($\"{$\"{@long:b}\".Length} || {@long:b} || {@long}\");"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".NET (C#)",
   "language": "C#",
   "name": ".net-csharp"
  },
  "language_info": {
   "name": "polyglot-notebook"
  },
  "polyglot_notebook": {
   "kernelInfo": {
    "defaultKernelName": "csharp",
    "items": [
     {
      "aliases": [],
      "languageName": "csharp",
      "name": "csharp"
     }
    ]
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
